<?php
/**
 * Created by PhpStorm.
 * User: FDG296
 * Date: 2017/7/10
 * Time: 15:33
 */
namespace backend\models;

use Yii;
use yii\db\ActiveRecord;
use phpDocumentor\Reflection\DocBlock\Tags\VarTest;

class GoodsRelation extends ActiveRecord{
    public static function tableName(){
        return '{{%goods_relation}}';
    }

    public function rules(){
        return [
            ['creator','getCreator'],
//             ['create_time','date']
        ];
    }

    /**
     * @获取创建人
     */
    public function getCreator(){
        $userInfo = \common\helps\tools::getloginUserInfo();
        if($userInfo){
            $userName = $userInfo->userName;
        }else{
            $userName = '';
        }
        return $userName;
    }
    
    //获取商品搭配
    public function getGoodsGroupList($id){
        $where = ['use_flg'=>1,'relation_key'=>'goods_'.$id];
        //获取主商品id
        $result = $this::find()->where($where)->limit(4)->orderBy('sort asc')->select('main_goods_id')->asArray()->all();
        if(!empty($result)){
            $main_goods_id = array_column($result,'main_goods_id');
        }else{
            $main_goods_id = '';
        }
        return $main_goods_id;
    }
}